#!/bin/bash

source_functions()
{
	. conf/itennis.conf
	. scripts/log_print
	. scripts/exec_remote
	
}

main()
{
	source_functions
	timeout=$REMOTE_TIMEOUT
	port=$REMOTE_PORT
	grep -v "^#" ${RAID_CONF} | while read line
	do
		host_ip=`echo $line | awk '{print $1}'`
		username=`echo $line | awk '{print $2}'`
		password=`echo $line | awk '{print $3}'`
		raidmode=`echo $line | awk '{print $4}'`
		disknum=`echo $line | awk '{print $5}'`
		src="tools/megacli"
		tmpdir=$TMPDIR
		exec_cmd_r $port $timeout $host_ip $username $password "mkdir -p $tmpdir" | tee -a /var/log/iTennis/${host_ip}.log
		cp_file_to_r $port $timeout $host_ip $username $password "$src" "$tmpdir"
                exec_cmd_r $port 30 $host_ip $username $password "sh $tmpdir/megacli/check.sh $disknum $raidmode" | tee -a /var/log/iTennis/${host_ip}.log
		if [ $? = 0 ];then
                        log INFO "exec_cmd_r $port $timeout $host_ip $username $password \"sh $tmpdir/megacli/check.sh $disknum $raidmode\" execute in $host_ip success"
                else
                        log ERROR "exec_cmd_r $port $timeout $host_ip $username $password \"sh $tmpdir/megacli/check.sh $disknum $raidmode\" execute in $host_ip failed"
                fi
		exec_cmd_r $port $timeout $host_ip $username $password "rm -rf $tmpdir" | tee -a /var/log/iTennis/${host_ip}.log
                if [ $? = 0 ];then
                        log INFO "log clen execute in $host_ip success"
                else
                        log ERROR "log clen execute in $host_ip failed"
                fi

	done 
}
umask 027
main "$@"
exit $? 
